$(function () {
    $('#userName').val(localStorage.getItem('userName'));//页面刷新保存用户登陆账号信息
    $('#passWord').val(localStorage.getItem('passWord'));
    $.post(Feng.ctxPath + "/outpatientManagement/getList", function (data) {
        var txt = '';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].simplename + '">' + data[i].simplename + '</option>';
        }
        document.getElementById('outpatientName').innerHTML = txt;
        var optionALL = $("#outpatientName").find("option");
        for (var q = 0; q < optionALL.length; q++) {
            if (localStorage.getItem('outpatientName') === optionALL[q].innerHTML) {
                optionALL[q].selected = true;
            }
        }
    }, "json");

    $('#submit_login').click(function () {
        var userName = $('#userName').val();
        var passWord = $('#passWord').val();
        var outpatientName = $('#outpatientName').val();
        localStorage.setItem('userName', userName);
        localStorage.setItem('passWord', passWord);
        localStorage.setItem('outpatientName', outpatientName);
        if(outpatientName == "请选择门店"){
            alert("请选择门店!");
        }else {
            $.ajax({
                url: Feng.ctxPath + "/weixin/loginWx",
                type: "post",
                data: {
                    "username": userName,
                    "outpatientName": outpatientName,
                    "password": passWord
                },
                success: function (data) {
                    window.location.href = Feng.ctxPath + "/weixin/index";
                },
                error: function (data) {
                    alert('权限被限制，请联系管理员!');
                    window.location.href = Feng.ctxPath + "/weixin/loginWx";
                }
            });
        }
    });

    var viewHeight = window.innerHeight;
    $("input").focus(function(){
        var signInTop = $(".signIn").offset().top;
        var btnTop = $(".btnBox").offset().top;
        $(".Resetbody,html").css({"height":viewHeight});
        $(".signIn").css('top',signInTop);
        $(".btnBox").css('top',btnTop);
    });

    var code = "";
    if (window.location.href.indexOf("code") != -1) {
        code = window.location.href.split("code=")[1].split("&state")[0];
    }
    $.ajax({
        url: Feng.ctxPath + "/wxWeixin/getOpenid",
        type: "GET",
        data: {"code": code},
        success: function (data) {

        },
        error: function (data) {

        }
    });
});